package ejb.metrica.seguridad.control;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * The Data Transfer Object class.
 * Created 15/05/2006 03:29:56 PM
 * @author jsanchez
 */
public class LoginDTO implements java.io.Serializable {

    private java.lang.Long ID;
    private java.lang.String USUARIO;
    private java.lang.Long ROL;
    private boolean DIRTY = false; //dirty flag
    
    public LoginDTO(){
        
    }

    public void setROL(Long ROL) {
        this.ROL = ROL;
    }

    public Long getROL() {
        return ROL;
    }

    private void setDIRTY(){
        DIRTY = true;
    }
    
    public boolean isDIRTY(){
        return DIRTY;
    }
    
    public void resetDIRTY(){
        DIRTY = false;
    }
    
    public java.lang.Long getID(){ return ID; }
    public void setID(java.lang.Long ID){
        this.ID = ID;
        setDIRTY();
    }

    public String getUSUARIO() {return USUARIO;}
    public void setUSUARIO(String USUARIO) {
        this.USUARIO = USUARIO;
        setDIRTY();
    }
    

    
    // populate DTO from Object
    public void POPULATE(Object o) {
        Method[] methods = o.getClass().getMethods();
        for (int i = 0; i < methods.length; i++) {
            try{
                String methodName = methods[i].getName();
                if ((methodName.startsWith("get") ||
                        methodName.startsWith("is"))
                        && Modifier.isPublic(methods[i].getModifiers())
                        && methods[i].getParameterTypes().length == 0
                        && !methodName.equals("getClass")) {
                    String setMethodName = methodName.replaceFirst(methodName.startsWith("get")?"get":"is","set");
                    getClass().getMethod(setMethodName,new Class[]{methods[i].getReturnType()}).
                            invoke(this, new Object[]{methods[i].invoke(o,new Object())});
                }
            }catch(IllegalAccessException ilE){
                ilE.printStackTrace();
            }catch(InvocationTargetException invE){
                invE.printStackTrace();
            }catch(NoSuchMethodException noE){
                // Don't find setMethod for field
            }
        }
    }
    
    
    /**
     * @see java.lang.Object#toString()
     */
    public String toSTRING(){
        return getClass().getName() + "[" +
                "id: " + this.ID + ", " +
                "usuario: " + this.USUARIO+ "]";
    }    
}